﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using tuwien.auto.eibclient;

namespace KNXFramework.KNXObjects.ValueObjects.Unsigned
{
    internal class U32ObjectValue : UIntObjectValue
    {
        public U32ObjectValue(string value) : base(value)
        {
        }
        public U32ObjectValue(EIBBuffer buffer)
        {
            m_Value = (uint)((buffer.data[2] << 24) | (buffer.data[3] << 16) | (buffer.data[4] << 8) | buffer.data[5]);
        }
        public override void AdaptBufferBeforeSending(bool isWrite, EIBBuffer buffer)
        {
            byte[] b = new byte[6];
            b[0] = buffer.data[0];
            b[1] = (byte)(isWrite ? 0x80 : 0x40);
            b[2] = (byte)((m_Value & 0xff000000)>>24);
            b[3] = (byte)((m_Value & 0xff0000)>>16);
            b[4] = (byte)((m_Value & 0xff00) >> 8);
            b[5] = (byte)(m_Value & 0xff);
            buffer.data = b;
        } 
    }
}
